-
Notifications
You must be signed in to change notification settings - Fork 423
feat(shared): Remove SWR #7568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(shared): Remove SWR #7568
Conversation
🦋 Changeset detectedLatest commit: aa68070 The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
!allow-major |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
|
Caution Review failedAn error occurred during the review process. Please try again later. 📝 WalkthroughWalkthroughRemoves SWR-based implementations and virtual data-hook shims across the shared package, deletes the CLERK_USE_RQ flag and related typings/config, promotes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @packages/shared/src/react/billing/useInitializePaymentMethod.tsx:
- Around line 22-74: Call useClearQueriesOnSignOut to purge the cached
initializePaymentMethod result on sign-out: import useClearQueriesOnSignOut and
invoke it in useInitializePaymentMethod (after you compute queryKey / query)
with isSignedOut: user === null, authenticated: the authenticated value from
useUserContext (or equivalent boolean available from user context), and
stableKeys: queryKey (or the stableKey used by other billing hooks). This
ensures the sensitive externalClientSecret in initializedPaymentMethod is
removed from the query cache on sign-out.
In @packages/shared/src/react/hooks/usePagesOrInfinite.tsx:
- Around line 201-208: The non-infinite pagination logic multiplies offsetCount
twice, producing wrong results when initialPageRef.current > 1; update the
hasNextPage and hasPreviousPage conditions to stop multiplying offsetCount by
pageSizeRef.current again: when not triggerInfinite, set hasNextPage to count -
offsetCount > page * pageSizeRef.current, and set hasPreviousPage to (page - 1)
* pageSizeRef.current > offsetCount; keep triggerInfinite branches using
infiniteQuery as-is and reference the symbols offsetCount, pageSizeRef.current,
initialPageRef.current, triggerInfinite, infiniteQuery, hasNextPage, and
hasPreviousPage when making the change.
📜 Review details
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (58)
.changeset/polite-cars-lose.md.changeset/remove-swr-switches.mdpackages/clerk-js/package.jsonpackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/global.d.tspackages/shared/package.jsonpackages/shared/src/react/billing/useInitializePaymentMethod.rq.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.swr.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/billing/useStripeClerkLibs.rq.tsxpackages/shared/src/react/billing/useStripeClerkLibs.swr.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/billing/useStripeLoader.rq.tsxpackages/shared/src/react/billing/useStripeLoader.swr.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/clerk-swr.tspackages/shared/src/react/contexts.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/index.tspackages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.tspackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.rq.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.swr.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.rq.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.swr.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.rq.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.swr.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsxpackages/shared/src/react/hooks/useStatementQuery.rq.tsxpackages/shared/src/react/hooks/useStatementQuery.swr.tsxpackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/hooks/useSubscription.rq.tsxpackages/shared/src/react/hooks/useSubscription.swr.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/providers/SWRConfigCompat.rq.tsxpackages/shared/src/react/providers/SWRConfigCompat.swr.tsxpackages/shared/src/react/providers/SWRConfigCompat.tsxpackages/shared/src/types/virtual-data-hooks.d.tspackages/shared/tsconfig.jsonpackages/shared/tsdown.config.mtspackages/shared/vitest.config.mtspackages/shared/vitest.setup.mtspackages/ui/bundlewatch.config.jsonpackages/ui/package.jsonpackages/ui/src/contexts/CoreClerkContextWrapper.tsx
💤 Files with no reviewable changes (27)
- packages/shared/src/react/providers/SWRConfigCompat.tsx
- packages/shared/src/react/providers/SWRConfigCompat.swr.tsx
- packages/shared/src/react/hooks/usePaymentAttemptQuery.swr.tsx
- packages/shared/src/types/virtual-data-hooks.d.ts
- packages/shared/src/react/hooks/useAPIKeys.ts
- packages/shared/global.d.ts
- packages/shared/src/react/hooks/usePaymentAttemptQuery.rq.tsx
- packages/shared/src/react/hooks/useStatementQuery.swr.tsx
- packages/shared/src/react/billing/useStripeLoader.swr.tsx
- packages/shared/src/react/billing/useStripeLoader.rq.tsx
- packages/shared/src/react/hooks/useSubscription.rq.tsx
- packages/shared/vitest.setup.mts
- packages/shared/src/react/providers/SWRConfigCompat.rq.tsx
- packages/shared/src/react/hooks/usePlanDetailsQuery.rq.tsx
- packages/shared/src/react/billing/useInitializePaymentMethod.swr.tsx
- packages/shared/src/react/hooks/usePagesOrInfinite.swr.tsx
- packages/shared/src/react/hooks/usePagesOrInfinite.rq.tsx
- packages/shared/src/react/billing/useInitializePaymentMethod.rq.tsx
- packages/shared/src/react/hooks/useSubscription.swr.tsx
- packages/shared/vitest.config.mts
- packages/shared/src/react/hooks/usePlanDetailsQuery.swr.tsx
- packages/shared/src/react/clerk-swr.ts
- packages/shared/src/react/hooks/useStatementQuery.rq.tsx
- packages/shared/src/react/hooks/useAPIKeys.swr.tsx
- packages/shared/tsdown.config.mts
- packages/shared/src/react/billing/useStripeClerkLibs.swr.tsx
- packages/shared/src/react/billing/useStripeClerkLibs.rq.tsx
🧰 Additional context used
📓 Path-based instructions (19)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
All code must pass ESLint checks with the project's configuration
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/package.jsonpackages/ui/package.jsonpackages/ui/bundlewatch.config.jsonpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/tsconfig.jsonpackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/clerk-js/package.jsonpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
packages/**/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Follow established naming conventions (PascalCase for components, camelCase for variables)
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
packages/**/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Implement type guards forunknowntypes using the patternfunction isType(value: unknown): value is Type
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details in classes
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like<T extends { id: string }>
Use utility types likeOmit,Partial, andPickfor data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Useconst assertionswithas constfor literal types
Usesatisfiesoperator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Use ESLint with custom configurations tailored for different package types
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Use Prettier for code formatting across all packages
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/package.jsonpackages/ui/package.jsonpackages/ui/bundlewatch.config.jsonpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/tsconfig.jsonpackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/clerk-js/package.jsonpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*
⚙️ CodeRabbit configuration file
If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.
**/*: Only comment on issues that would block merging, ignore minor or stylistic concerns.
Restrict feedback to errors, security risks, or functionality-breaking problems.
Do not post comments on code style, formatting, or non-critical improvements.
Keep reviews short: flag only issues that make the PR unsafe to merge.
Group similar issues into a single comment instead of posting multiple notes.
Skip repetition: if a pattern repeats, mention it once at a summary level only.
Do not add general suggestions, focus strictly on merge-blocking concerns.
If there are no critical problems, respond with minimal approval (e.g., 'Looks good'). Do not add additional review.
Avoid line-by-line commentary unless it highlights a critical bug or security hole.
Highlight only issues that could cause runtime errors, data loss, or severe maintainability issues.
Ignore minor optimization opportunities, focus solely on correctness and safety.
Provide a top-level summary of critical blockers rather than detailed per-line notes.
Comment only when the issue must be resolved before merge, otherwise remain silent.
When in doubt, err on the side of fewer comments, brevity and blocking issues only.
Avoid posting any refactoring issues.
Files:
packages/shared/src/react/hooks/useClearQueriesOnSignOut.tspackages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/package.jsonpackages/ui/package.jsonpackages/ui/bundlewatch.config.jsonpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/tsconfig.jsonpackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/index.tspackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/clerk-js/package.jsonpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features
Files:
packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.tsx: Use error boundaries in React components
Minimize re-renders in React components
**/*.tsx: Use proper type definitions for props and state in React components
Leverage TypeScript's type inference where possible in React components
Use proper event types for handlers in React components
Implement proper generic types for reusable React components
Use proper type guards for conditional rendering in React components
Files:
packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use real Clerk instances for integration tests
Files:
packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.tspackages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.tspackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
**/*.{md,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Update documentation for API changes
Files:
packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components (e.g.,UserProfile,NavigationMenu)
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Separate UI components from business logic components
Use useState for simple state management in React components
Use useReducer for complex state logic in React components
Implement proper state initialization in React components
Use proper state updates with callbacks in React components
Implement proper state cleanup in React components
Use Context API for theme/authentication state management
Implement proper state persistence in React applications
Use React.memo for expensive components
Implement proper useCallback for handlers in React components
Use proper useMemo for expensive computations in React components
Implement proper virtualization for lists in React components
Use proper code splitting with React.lazy in React applications
Implement proper cleanup in useEffect hooks
Use proper refs for DOM access in React components
Implement proper event listener cleanup in React components
Use proper abort controllers for fetch in React components
Implement proper subscription cleanup in React components
Use proper HTML elements for semantic HTML in React components
Implement proper ARIA attributes for accessibility in React components
Use proper heading hierarchy in React components
Implement proper form labels in React components
Use proper button types in React components
Implement proper focus management for keyboard navigation in React components
Use proper keyboard shortcuts in React components
Implement proper tab order in React components
Use proper ...
Files:
packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/useOrganizationList.tsxpackages/shared/src/react/hooks/useStatementQuery.tsxpackages/shared/src/react/billing/useInitializePaymentMethod.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/clerk-js/src/test/create-fixtures.tsxpackages/shared/src/react/hooks/useAPIKeys.tsxpackages/shared/src/react/hooks/useOrganization.tsxpackages/shared/src/react/hooks/createBillingPaginatedHook.tsxpackages/shared/src/react/hooks/useSubscription.tsxpackages/shared/src/react/hooks/__tests__/wrapper.tsxpackages/shared/src/react/contexts.tsxpackages/shared/src/react/billing/useStripeLoader.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/billing/useStripeClerkLibs.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsxpackages/shared/src/react/hooks/usePaymentAttemptQuery.tsxpackages/shared/src/react/hooks/usePagesOrInfinite.tsxpackages/ui/src/contexts/CoreClerkContextWrapper.tsxpackages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{test,spec}.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{test,spec}.{jsx,tsx}: Use React Testing Library for unit testing React components
Test component behavior, not implementation details
Use proper test queries in React Testing Library tests
Implement proper test isolation in React component tests
Use proper test coverage in React component tests
Test component interactions in integration tests
Use proper test data in React component tests
Implement proper test setup in React component tests
Use proper test cleanup in React component tests
Implement proper test assertions in React component tests
Use proper test structure for React component tests
Files:
packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsxpackages/shared/src/react/hooks/__tests__/usePlans.spec.tsxpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsxpackages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
packages/*/package.json
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
packages/*/package.json: Packages should export TypeScript types alongside runtime code
Follow semantic versioning for all packagesAll packages must be published under @clerk namespace
packages/*/package.json: Framework packages should depend on@clerk/clerk-jsfor core functionality
@clerk/sharedshould be a common dependency for most packages in the monorepo
Files:
packages/shared/package.jsonpackages/ui/package.jsonpackages/clerk-js/package.json
**/package.json
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Use pnpm as the package manager for this monorepo
Files:
packages/shared/package.jsonpackages/ui/package.jsonpackages/clerk-js/package.json
**/index.ts
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Avoid barrel files (index.ts re-exports) as they can cause circular dependencies
Files:
packages/shared/src/react/hooks/index.ts
🧬 Code graph analysis (14)
packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts (1)
packages/clerk-js/src/core/auth/AuthCookieService.ts (1)
isSignedOut(98-103)
packages/shared/src/react/hooks/useOrganizationList.tsx (2)
packages/react/src/isomorphicClerk.ts (1)
user(730-736)packages/shared/src/react/hooks/createCacheKeys.ts (1)
createCacheKeys(7-23)
packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts (1)
packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts (2)
withInfiniteKey(6-6)useClearQueriesOnSignOut(28-61)
packages/shared/src/react/billing/useInitializePaymentMethod.tsx (8)
packages/shared/src/types/billing.ts (2)
ForPayerType(89-89)BillingInitializedPaymentMethodResource(369-382)packages/shared/src/react/contexts.tsx (2)
useOrganizationContext(119-119)useUserContext(122-122)packages/shared/src/react/index.ts (2)
useOrganizationContext(15-15)useUserContext(18-18)packages/shared/src/react/hooks/useBillingHookEnabled.ts (1)
useBillingHookEnabled(7-27)packages/shared/src/react/clerk-rq/useQuery.ts (1)
useClerkQuery(39-41)packages/shared/src/react/clerk-rq/keep-previous-data.ts (1)
defineKeepPreviousDataFn(4-11)packages/shared/src/react/clerk-rq/use-clerk-query-client.ts (1)
useClerkQueryClient(84-84)packages/clerk-js/src/core/modules/billing/payment-source-methods.ts (1)
initializePaymentMethod(20-30)
packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx (1)
packages/clerk-js/src/test/utils.ts (1)
waitFor(73-73)
packages/clerk-js/src/test/create-fixtures.tsx (2)
packages/ui/src/contexts/CoreClerkContextWrapper.tsx (1)
CoreClerkContextWrapper(21-67)packages/clerk-js/src/test/core-fixtures.ts (1)
clerkMock(249-256)
packages/shared/src/react/hooks/useAPIKeys.tsx (2)
packages/shared/src/react/hooks/createCacheKeys.ts (1)
createCacheKeys(7-23)packages/shared/src/react/stable-keys.ts (1)
STABLE_KEYS(30-51)
packages/shared/src/react/hooks/useOrganization.tsx (3)
packages/react/src/isomorphicClerk.ts (1)
organization(738-744)packages/shared/src/react/hooks/createCacheKeys.ts (1)
createCacheKeys(7-23)packages/shared/src/react/stable-keys.ts (1)
STABLE_KEYS(30-51)
packages/shared/src/react/hooks/createBillingPaginatedHook.tsx (1)
packages/react/src/isomorphicClerk.ts (1)
organization(738-744)
packages/shared/src/react/contexts.tsx (1)
packages/shared/src/react/index.ts (1)
OrganizationProvider(9-9)
packages/shared/src/react/billing/useStripeLoader.tsx (4)
packages/shared/src/react/billing/useStripeClerkLibs.tsx (1)
UseStripeClerkLibsResult(14-14)packages/shared/src/react/hooks/useBillingHookEnabled.ts (1)
useBillingHookEnabled(7-27)packages/shared/src/react/clerk-rq/useQuery.ts (1)
useClerkQuery(39-41)packages/shared/src/react/clerk-rq/keep-previous-data.ts (1)
defineKeepPreviousDataFn(4-11)
packages/shared/src/react/billing/useStripeClerkLibs.tsx (4)
packages/shared/src/react/hooks/index.ts (1)
useClerk(10-10)packages/shared/src/react/hooks/useBillingHookEnabled.ts (1)
useBillingHookEnabled(7-27)packages/shared/src/react/clerk-rq/useQuery.ts (1)
useClerkQuery(39-41)packages/shared/src/react/clerk-rq/keep-previous-data.ts (1)
defineKeepPreviousDataFn(4-11)
packages/ui/src/contexts/CoreClerkContextWrapper.tsx (1)
packages/shared/src/react/contexts.tsx (1)
OrganizationProvider(112-112)
packages/shared/src/react/hooks/usePlanDetailsQuery.tsx (7)
packages/shared/src/react/hooks/usePlanDetailsQuery.types.ts (2)
UsePlanDetailsQueryParams(7-28)PlanDetailsQueryResult(33-50)packages/shared/src/react/contexts.tsx (1)
useClerkInstanceContext(116-116)packages/shared/src/react/index.ts (1)
useClerkInstanceContext(12-12)packages/shared/src/react/hooks/usePlanDetailsQuery.shared.ts (1)
usePlanDetailsQueryCacheKeys(6-22)packages/shared/src/react/hooks/useBillingHookEnabled.ts (1)
useBillingHookEnabled(7-27)packages/shared/src/react/clerk-rq/useQuery.ts (1)
useClerkQuery(39-41)packages/shared/src/react/clerk-rq/keep-previous-data.ts (1)
defineKeepPreviousDataFn(4-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (28)
- GitHub Check: Unit Tests (shared, clerk-js, RQ)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (**)
- GitHub Check: Integration Tests (billing, chrome, RQ)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (quickstart, chrome, 15)
- GitHub Check: Integration Tests (sessions:staging, chrome)
- GitHub Check: Integration Tests (quickstart, chrome, 16)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (nextjs, chrome, 16, RQ)
- GitHub Check: Integration Tests (handshake, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (handshake:staging, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 16)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (machine, chrome, RQ)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (14)
.changeset/polite-cars-lose.md (1)
1-5: Changeset entry is well-formed and accurately documents the fix.The changeset correctly declares a patch bump for
@clerk/sharedwith a clear, concise description that accurately reflects theuseClearQueriesOnSignOuthook fix referenced in the PR objectives.packages/shared/tsconfig.json (1)
26-30: Configuration cleanup looks correct.The removal of virtual path aliases and
virtual-data-hooks.d.tsfrom the include array aligns with the PR's objective to remove SWR and the virtual data-hooks system. The TypeScript compiler will catch any remaining references to removed modules during build.packages/shared/src/react/hooks/__tests__/wrapper.tsx (1)
3-3: The wrapper change is safe. All context provisioning in tests is handled via module-level mocks (vi.mock('../../contexts', ...)), not by the wrapper component itself. The wrapper serves only as a container forrenderHookand the change fromSWRConfigCompatto a simple fragment does not affect test behavior or functionality.packages/shared/src/react/hooks/useAPIKeys.tsx (1)
105-111: LGTM!The explicit null check for
isSignedInand hardcodedauthenticated: truecorrectly implement the PR objectives to fix hook order issues while maintaining proper authentication gating.packages/shared/src/react/hooks/index.ts (1)
24-24: LGTM!Documentation correctly updated to reflect React Query as the sole implementation.
.changeset/remove-swr-switches.md (1)
1-5: LGTM!Changeset correctly documents the major breaking change.
packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts (1)
725-725: LGTM!Test correctly updated to remove environment-based branching, now expecting consistent React Query behavior.
packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx (1)
92-92: LGTM!Tests correctly updated to remove environment-based conditionals, expecting consistent React Query revalidation behavior across all scenarios.
packages/shared/src/react/hooks/useStatementQuery.tsx (1)
1-59: LGTM!The hook implementation correctly:
- Guards query execution with
queryEnabledcheck before callingclerk.billing.getStatement- Clears queries on sign-out via
useClearQueriesOnSignOut- Returns a stable result shape matching
StatementQueryResult- Follows the same patterns as other billing hooks in this PR
packages/shared/src/react/contexts.tsx (1)
71-81: LGTM!The
OrganizationProvidersimplification correctly removes the SWR wrapper dependency, aligning with the PR's objective to consolidate on React Query.packages/shared/src/react/hooks/useSubscription.tsx (1)
23-81: LGTM!The implementation correctly:
- Records telemetry on first render only (via
recordedRef)- Clears queries on sign-out
- Normalizes error to
undefinedfor backward compatibility with SWR-based API- Provides
revalidatefunction via query client invalidationpackages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx (1)
94-133: LGTM!The test updates correctly remove environment-flag conditional branches. The unified expectations for sign-out behavior (data becomes
undefinedeven withkeepPreviousData=true) align with the fix for USER-4251, ensuring stale data is properly cleared on sign-out.packages/shared/src/react/hooks/usePlanDetailsQuery.tsx (1)
11-44: LGTM!The implementation correctly:
- Sets
authenticated: falseforuseBillingHookEnabledsince plan details are public data- Uses
initialDataUpdatedAt: 0to treat initial data as immediately stale- Omits
useClearQueriesOnSignOutappropriately since this hook doesn't require authenticationpackages/shared/src/react/hooks/usePagesOrInfinite.tsx (1)
13-112: Core hook structure looks good.The implementation correctly:
- Handles both paginated and infinite query modes
- Uses
useClearQueriesOnSignOutwith proper cleanup callback to reset pagination state- Manages force re-renders for cache-only updates via
forceUpdateCounter
| function useInitializePaymentMethod(options?: InitializePaymentMethodOptions): UseInitializePaymentMethodResult { | ||
| const { for: forType } = options ?? {}; | ||
| const { organization } = useOrganizationContext(); | ||
| const user = useUserContext(); | ||
|
|
||
| const resource = forType === 'organization' ? organization : user; | ||
|
|
||
| const billingEnabled = useBillingHookEnabled(options); | ||
|
|
||
| const queryKey = useMemo(() => { | ||
| return ['billing-payment-method-initialize', { resourceId: resource?.id }] as const; | ||
| }, [resource?.id]); | ||
|
|
||
| const isEnabled = Boolean(resource?.id) && billingEnabled; | ||
|
|
||
| const query = useClerkQuery({ | ||
| queryKey, | ||
| queryFn: async () => { | ||
| if (!resource) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return resource.initializePaymentMethod({ | ||
| gateway: 'stripe', | ||
| }); | ||
| }, | ||
| enabled: isEnabled, | ||
| staleTime: 1_000 * 60, | ||
| refetchOnWindowFocus: false, | ||
| placeholderData: defineKeepPreviousDataFn(true), | ||
| }); | ||
|
|
||
| const [queryClient] = useClerkQueryClient(); | ||
|
|
||
| const initializePaymentMethod = useCallback(async () => { | ||
| if (!resource) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const result = await resource.initializePaymentMethod({ | ||
| gateway: 'stripe', | ||
| }); | ||
|
|
||
| queryClient.setQueryData(queryKey, result); | ||
|
|
||
| return result; | ||
| }, [queryClient, queryKey, resource]); | ||
|
|
||
| return { | ||
| initializedPaymentMethod: query.data ?? undefined, | ||
| initializePaymentMethod, | ||
| }; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for useClearQueriesOnSignOut usage in billing hooks
rg -n "useClearQueriesOnSignOut" packages/shared/src/react/billing/ packages/shared/src/react/hooks/Repository: clerk/javascript
Length of output: 2757
🏁 Script executed:
#!/bin/bash
# Check usePaymentAttemptQuery to understand why it uses useClearQueriesOnSignOut
cat -n packages/shared/src/react/hooks/usePaymentAttemptQuery.tsxRepository: clerk/javascript
Length of output: 2472
🏁 Script executed:
#!/bin/bash
# Also check the full useInitializePaymentMethod implementation with imports
cd packages/shared/src/react/billing
cat -n useInitializePaymentMethod.tsx | head -80Repository: clerk/javascript
Length of output: 2884
🏁 Script executed:
#!/bin/bash
# Check what BillingInitializedPaymentMethodResource contains
rg -A 10 "BillingInitializedPaymentMethodResource" packages/shared/src/types/ | head -30Repository: clerk/javascript
Length of output: 2248
🏁 Script executed:
#!/bin/bash
# Check if there's any other sign-out handling or cache invalidation logic in useInitializePaymentMethod context
rg -n "sign.*out|Sign.*Out" packages/shared/src/react/billing/ packages/shared/src/react/hooks/useBillingHookEnabled.tsxRepository: clerk/javascript
Length of output: 157
🏁 Script executed:
#!/bin/bash
# Search for useBillingHookEnabled to understand if it has special sign-out logic
find packages/shared/src -name "*useBillingHookEnabled*"Repository: clerk/javascript
Length of output: 116
🏁 Script executed:
#!/bin/bash
# Check other billing hooks to see the pattern of useClearQueriesOnSignOut
grep -l "useClearQueriesOnSignOut" packages/shared/src/react/hooks/*.tsxRepository: clerk/javascript
Length of output: 279
🏁 Script executed:
#!/bin/bash
# Check useBillingHookEnabled
cat -n packages/shared/src/react/hooks/useBillingHookEnabled.tsRepository: clerk/javascript
Length of output: 1394
🏁 Script executed:
#!/bin/bash
# Check useSubscription to see the full pattern
cat -n packages/shared/src/react/hooks/useSubscription.tsxRepository: clerk/javascript
Length of output: 3261
Add useClearQueriesOnSignOut to clear cached payment method data on sign-out.
The hook caches the payment method initialization result containing externalClientSecret (a sensitive Stripe client secret) but doesn't clear this cache when the user signs out. This is inconsistent with other billing hooks (usePaymentAttemptQuery, useSubscription) which explicitly call useClearQueriesOnSignOut({isSignedOut: user === null, authenticated, stableKeys: stableKey}) to clear sensitive cached data. Add this call to prevent the client secret from persisting in the query cache after sign-out.
🤖 Prompt for AI Agents
In @packages/shared/src/react/billing/useInitializePaymentMethod.tsx around
lines 22 - 74, Call useClearQueriesOnSignOut to purge the cached
initializePaymentMethod result on sign-out: import useClearQueriesOnSignOut and
invoke it in useInitializePaymentMethod (after you compute queryKey / query)
with isSignedOut: user === null, authenticated: the authenticated value from
useUserContext (or equivalent boolean available from user context), and
stableKeys: queryKey (or the stableKey used by other billing hooks). This
ensures the sensitive externalClientSecret in initializedPaymentMethod is
removed from the query cache on sign-out.
…on bug - Extract pagination calculations into pure utility functions for better testability: - calculateOffsetCount: calculates items to skip based on initial page - calculatePageCount: calculates total pages accounting for offset - calculateHasNextPage: determines if more pages exist - calculateHasPreviousPage: determines if previous pages exist - Fix hasNextPage/hasPreviousPage double multiplication bug where offsetCount was incorrectly multiplied by pageSizeRef.current again - Add comprehensive unit tests for pagination utilities (21 test cases)
|
!snapshot |
|
Hey @jacekradko - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact |
Description
Also adding fixes from #7544
Fixes: USER-4251
Snapshot deployed to https://github.com/clerk/dashboard/pull/7966
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Dependencies
Bug Fixes
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.